package org.proddevplm.business.tools;

import java.util.HashMap;
import java.util.Map;

import org.proddevplm.business.api.IAdapter;
import org.proddevplm.business.tools.constants.ToolsConstants;
import org.proddevplm.helpers.ManagerUtil;

public class ToolsAdapter implements IAdapter{

	@Override
	public Object adapt(int command, Map<String, Object> dataObject) {
		
		Object adaptedObject = null;
		Map<String, Object> analysisMap = new HashMap<String, Object>();
		
		switch (command){
		case ToolsConstants.COMPETITORS_ANALYSIS_FORM1:
			
			analysisMap.put("productConcept", ((String[])dataObject.get("concept"))[0]);
			analysisMap.put("productFamily", ((String[])dataObject.get("family"))[0]);
			
			analysisMap.put("competitorsList", ManagerUtil.getStringFromReq(dataObject.get("competitorsList")));
			String competitorsList = (String)analysisMap.get("competitorsList");
			String[] competitorsArray = competitorsList.split("~");
			analysisMap.put("competitorsArray", competitorsArray);		
			
			adaptedObject = analysisMap;
			break;
		
		
		case ToolsConstants.COMPETITORS_ANALYSIS_FORM2:
			analysisMap.put("compProductName", ((String[])dataObject.get("cpName"))[0]);
			analysisMap.put("competitor", ((String[])dataObject.get("productCompetitor"))[0]);
			
			analysisMap.put("characteristicsList", ManagerUtil.getStringFromReq(dataObject.get("characteristicsList")));
			String characteristicsList = (String) analysisMap.get("characteristicsList");
			String[] characteristicsArray = characteristicsList.split("~");
			analysisMap.put("characteristicsArray", characteristicsArray);
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activitySelect")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.SWOT:		
			
			analysisMap.put("analysisName", ManagerUtil.getStringFromReq(dataObject.get("analysisName")));
			analysisMap.put("competitor", ManagerUtil.getStringFromReq(dataObject.get("compSelect")));
			analysisMap.put("product", ManagerUtil.getStringFromReq(dataObject.get("prodSelect")));
			analysisMap.put("strengthsList", ManagerUtil.getStringFromReq(dataObject.get("strengthsList")));
			analysisMap.put("weaksList", ManagerUtil.getStringFromReq(dataObject.get("weaksList")));
			analysisMap.put("oppsList", ManagerUtil.getStringFromReq(dataObject.get("oppsList")));
			analysisMap.put("threatsList", ManagerUtil.getStringFromReq(dataObject.get("threatsList")));
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activitySelect")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.STAKEHOLDERS:
			
			analysisMap.put("shName", ManagerUtil.getStringFromReq(dataObject.get("shName")));			
			analysisMap.put("shDetails", ManagerUtil.getStringFromReq(dataObject.get("shDetails")));
			analysisMap.put("type", ManagerUtil.getStringFromReq(dataObject.get("type")));
			analysisMap.put("lcStages", ManagerUtil.getStringFromReq(dataObject.get("lcStages")));
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.REM_STAKEHOLDER:
			analysisMap.put("shName", ManagerUtil.getStringFromReq(dataObject.get("shName")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.REQUIREMENTS:
			
			analysisMap.put("requirement", ManagerUtil.getStringFromReq(dataObject.get("requirement")));
			analysisMap.put("description", ManagerUtil.getStringFromReq(dataObject.get("description")));
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.REM_REQUIREMENT:
			analysisMap.put("requirement", ManagerUtil.getStringFromReq(dataObject.get("requirement")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.EDIT_REQUIREMENT:
			analysisMap.put("requirementId", ManagerUtil.getStringFromReq(dataObject.get("requirementId")));
			analysisMap.put("editedRequirement", ManagerUtil.getStringFromReq(dataObject.get("editedRequirement")));
			analysisMap.put("editedReqDesc", ManagerUtil.getStringFromReq(dataObject.get("editedReqDesc")));
			analysisMap.put("newSHforReq", ManagerUtil.getStringFromReq(dataObject.get("newSHforReq")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.ADD_EXTRA_REQUIREMENT:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("stakeholder", ManagerUtil.getStringFromReq(dataObject.get("stakeholder")));
			analysisMap.put("requirement", ManagerUtil.getStringFromReq(dataObject.get("requirement")));
			analysisMap.put("description", ManagerUtil.getStringFromReq(dataObject.get("description")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.PRIORITIZE:
			analysisMap.put("matrixSize", ManagerUtil.getStringFromReq(dataObject.get("matrixSize")));
			analysisMap.put("dataType", ManagerUtil.getStringFromReq(dataObject.get("dataType")));
			
			String elementsList = ManagerUtil.getStringFromReq(dataObject.get("elements"));
			String[] elements = elementsList.split("~");
			analysisMap.put("elements", elements);
			
			int matrixSize = Integer.valueOf(ManagerUtil.getStringFromReq(dataObject.get("matrixSize")));			
			String matrixValuesList = ManagerUtil.getStringFromReq(dataObject.get("matrixValues"));
			String[] matrixValuesArray = matrixValuesList.split("~");
			
			float[][] matrixValues = new float[matrixSize][matrixSize];
			
			int i=0; int j=0;
			int contor = 0;
			for (int index=0; index<matrixValuesArray.length; index++){
				float value = Float.valueOf(matrixValuesArray[index]);
				if(contor==(matrixSize-1)){
					matrixValues[i][j] = value;
					i++;
					j=0;
					contor = 0;
				}else{
					matrixValues[i][j] = value;
					j++;
					contor++;
					}
			}
			/*for (int r=0; r<matrixValues.length; r++) {
			     for (int c=0; c<matrixValues[r].length; c++) {
			         System.out.print(" " + matrixValues[r][c]);
			     }
			     System.out.println("");
			 }*/
			analysisMap.put("ahpMatrix", matrixValues);
			
			adaptedObject = analysisMap;
			break;
		
		case ToolsConstants.SUBMIT_AHP:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("ahpAnalysisName", ManagerUtil.getStringFromReq(dataObject.get("ahpAnalysisName")));
			analysisMap.put("elements", ManagerUtil.getStringFromReq(dataObject.get("elements")));
			analysisMap.put("ahpMatrix", ManagerUtil.getStringFromReq(dataObject.get("matrixValues")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.VOCT:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("requirement", ManagerUtil.getStringFromReq(dataObject.get("requirement")));
			analysisMap.put("stakeholder", ManagerUtil.getStringFromReq(dataObject.get("stakeholder")));
			analysisMap.put("whats", ManagerUtil.getStringFromReq(dataObject.get("whats")));
			analysisMap.put("hows", ManagerUtil.getStringFromReq(dataObject.get("hows")));
			analysisMap.put("whys", ManagerUtil.getStringFromReq(dataObject.get("whys")));
			analysisMap.put("whos", ManagerUtil.getStringFromReq(dataObject.get("whos")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.FUNCTIONS:
			String functionsList = ManagerUtil.getStringFromReq(dataObject.get("functionsList"));
			String[] functionsArray = functionsList.split("~");
			analysisMap.put("functionsArray", functionsArray);
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.CTQS:
			String ctqsList = ManagerUtil.getStringFromReq(dataObject.get("ctqsList"));
			String[] ctqsArray = ctqsList.split("~");
			analysisMap.put("ctqsArray", ctqsArray);
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.DE:
			String desList = ManagerUtil.getStringFromReq(dataObject.get("desList"));
			String[] desArray = desList.split("~");
			analysisMap.put("desArray", desArray);
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.UPDATE_SWOT:
			analysisMap.put("swotName", ManagerUtil.getStringFromReq(dataObject.get("swotName")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.REMOVE_FUNCTION:
			analysisMap.put("functionName", ManagerUtil.getStringFromReq(dataObject.get("functionName")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.REMOVE_CTQ:
			analysisMap.put("ctqName", ManagerUtil.getStringFromReq(dataObject.get("ctqName")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.REMOVE_DE:
			analysisMap.put("deName", ManagerUtil.getStringFromReq(dataObject.get("deName")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.ADD_CHANGE_REPORT:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("changeSubject", ManagerUtil.getStringFromReq(dataObject.get("changeSubject")));
			analysisMap.put("changeDetails", ManagerUtil.getStringFromReq(dataObject.get("changeDetails")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.PUGH_CRITERIA:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("criteria", ManagerUtil.getStringFromReq(dataObject.get("criteria")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.PUGH_CRITERIA_HIERARCHY:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("criteriaImportances", ManagerUtil.getStringFromReq(dataObject.get("criteriaImportances")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.PUGH_CONCEPTS:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("concepts", ManagerUtil.getStringFromReq(dataObject.get("concepts")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.PUGH_CALCULUS:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("pughMatrixValues", ManagerUtil.getStringFromReq(dataObject.get("pughMatrixValues")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.QFD_CALCULUS:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			analysisMap.put("qfdMatrixValues", ManagerUtil.getStringFromReq(dataObject.get("qfdMatrixValues")));
			analysisMap.put("qfdType", ManagerUtil.getStringFromReq(dataObject.get("qfdType")));
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.DFX:
			analysisMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			String guidelinesList = ManagerUtil.getStringFromReq(dataObject.get("guidelinesList"));
			String[] guidelinesIds = guidelinesList.split("~");
			analysisMap.put("guidelinesIds", guidelinesIds);
			adaptedObject = analysisMap;
			break;
			
		case ToolsConstants.REMOVE_DFXRM:
			analysisMap.put("dfxRMId", ManagerUtil.getStringFromReq(dataObject.get("dfxRMId")));
			adaptedObject = analysisMap;
			break;
		}
		
		return adaptedObject;
		
	}

}
